package com.cjd.common.utils

import android.view.View
import android.view.animation.AlphaAnimation
import android.view.animation.Animation
import android.view.animation.TranslateAnimation

/**
 * @Author chenjidong
 * @email 374122600@qq.com
 * created 2019/9/24
 * description 动画
 */
object AnimUtil {

    private val DEFAULT_TIME = 1000
    private val DEFAULT_HEIGHT = 600f

    fun showAlpha(view: View) {

        val alphaAnimation = AlphaAnimation(0.1f, 1.0f)
        alphaAnimation.duration = DEFAULT_TIME.toLong()
        view.startAnimation(alphaAnimation)

    }

    fun showAlpha(view: View, time: Int) {

        val alphaAnimation = AlphaAnimation(0.1f, 1.0f)
        alphaAnimation.duration = time.toLong()
        view.startAnimation(alphaAnimation)

    }

    fun goneAlpha(view: View) {

        val alphaAnimation = AlphaAnimation(1.0f, 0.0f)
        alphaAnimation.duration = DEFAULT_TIME.toLong()
        view.startAnimation(alphaAnimation)

    }

    fun goneAlpha(view: View, time: Int) {

        val alphaAnimation = AlphaAnimation(1.0f, 0.0f)
        alphaAnimation.duration = time.toLong()
        view.startAnimation(alphaAnimation)

    }

    fun upTranslate(view: View) {

        val translateAnimation = TranslateAnimation(0.0f, 0.0f, DEFAULT_HEIGHT, 0.0f)
        translateAnimation.duration = DEFAULT_TIME.toLong()
        view.startAnimation(translateAnimation)

    }

    fun upTranslate(view: View, time: Int) {

        val translateAnimation = TranslateAnimation(0.0f, 0.0f, DEFAULT_HEIGHT, 0.0f)
        translateAnimation.duration = time.toLong()
        view.startAnimation(translateAnimation)

    }

    fun upTranslate(view: View, y: Float) {

        val translateAnimation = TranslateAnimation(0.0f, 0.0f, y, 0.0f)
        translateAnimation.duration = DEFAULT_TIME.toLong()
        view.startAnimation(translateAnimation)

    }

    fun upTranslate(view: View, time: Int, y: Float) {

        val translateAnimation = TranslateAnimation(0.0f, 0.0f, y, 0.0f)
        translateAnimation.duration = time.toLong()
        view.startAnimation(translateAnimation)

    }

    fun downTranslate(view: View) {

        val translateAnimation = TranslateAnimation(0.0f, 0.0f, 0.0f, DEFAULT_HEIGHT)
        translateAnimation.duration = DEFAULT_TIME.toLong()
        view.startAnimation(translateAnimation)

    }

    fun downTranslate(view: View, time: Int) {

        val translateAnimation = TranslateAnimation(0.0f, 0.0f, 0.0f, DEFAULT_HEIGHT)
        translateAnimation.duration = time.toLong()
        view.startAnimation(translateAnimation)

    }

    fun downTranslate(view: View, y: Float) {

        val translateAnimation = TranslateAnimation(0.0f, 0.0f, 0.0f, y)
        translateAnimation.duration = DEFAULT_TIME.toLong()
        view.startAnimation(translateAnimation)

    }

    fun downTranslate(view: View, time: Int, y: Float) {

        val translateAnimation = TranslateAnimation(0.0f, 0.0f, 0.0f, y)
        translateAnimation.duration = time.toLong()
        view.startAnimation(translateAnimation)

    }

    fun downTranslate(view: View, time: Int, y: Float, listener: Animation.AnimationListener) {
        val translateAnimation = TranslateAnimation(0.0f, 0.0f, 0.0f, y)
        translateAnimation.duration = time.toLong()
        translateAnimation.setAnimationListener(listener)
        view.startAnimation(translateAnimation)

    }

    fun leftTranslate(view: View) {

        val translateAnimation = TranslateAnimation(DEFAULT_HEIGHT, 0.0f, 0.0f, 0.0f)
        translateAnimation.duration = DEFAULT_TIME.toLong()
        view.startAnimation(translateAnimation)

    }

    fun leftTranslate(view: View, time: Int) {

        val translateAnimation = TranslateAnimation(DEFAULT_HEIGHT, 0.0f, 0.0f, 0.0f)
        translateAnimation.duration = time.toLong()
        view.startAnimation(translateAnimation)

    }

    fun leftTranslate(view: View, x: Float) {

        val translateAnimation = TranslateAnimation(x, 0.0f, 0.0f, 0.0f)
        translateAnimation.duration = DEFAULT_TIME.toLong()
        view.startAnimation(translateAnimation)

    }

    fun leftTranslate(view: View, time: Int, x: Float) {

        val translateAnimation = TranslateAnimation(x, 0.0f, 0.0f, 0.0f)
        translateAnimation.duration = time.toLong()
        view.startAnimation(translateAnimation)

    }

    fun rightTranslate(view: View) {

        val translateAnimation = TranslateAnimation(0.0f, DEFAULT_HEIGHT, 0.0f, 0.0f)
        translateAnimation.duration = DEFAULT_TIME.toLong()
        view.startAnimation(translateAnimation)

    }

    fun rightTranslate(view: View, time: Int) {

        val translateAnimation = TranslateAnimation(0.0f, DEFAULT_HEIGHT, 0.0f, 0.0f)
        translateAnimation.duration = time.toLong()
        view.startAnimation(translateAnimation)

    }

    fun rightTranslate(view: View, x: Float) {

        val translateAnimation = TranslateAnimation(0.0f, x, 0.0f, 0.0f)
        translateAnimation.duration = DEFAULT_TIME.toLong()
        view.startAnimation(translateAnimation)

    }

    fun rightTranslate(view: View, time: Int, x: Float) {

        val translateAnimation = TranslateAnimation(0.0f, x, 0.0f, 0.0f)
        translateAnimation.duration = time.toLong()
        view.startAnimation(translateAnimation)

    }
}